{layout name="main"/}
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-3">
            <div class="ibox float-e-margins">
                <div class="ibox-content mailbox-content">
                    <div class="file-manager">
                        <a class="btn btn-block btn-primary compose-mail" href="{:url('admin/Mail/write')}">写信</a>
                        <div class="space-25"></div>
                        <h5>文件夹</h5>
                        <ul class="folder-list m-b-md" style="padding: 0">
                            <li>
                                <a href="{:url('admin/Mail/box',['usebox'=>'inbox'])}"> <i class="fa fa-inbox "></i> 收件箱 {if condition="$unread>0"}<span class="label label-warning pull-right">{$unread}</span>{/if}
                                </a>
                            </li>
                            <li>
                                <a href="{:url('admin/Mail/box',['usebox'=>'outbox'])}"> <i class="fa fa-envelope-o"></i> 发件箱</a>
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-9 animated fadeInRight">
            <div class="mail-box-header">

                <form method="get" action="{:url('admin/Mail/box',['usebox'=>$usebox])}" class="pull-right mail-search">
                    <div class="input-group">

                        <input type="text" class="form-control input-sm" name="keyword" value="{$keyword}" placeholder="搜索用户编号，用户昵称，邮件标题">
                        <div class="input-group-btn">
                            <button type="submit" class="btn btn-sm btn-primary">
                                搜索
                            </button>
                        </div>
                    </div>
                </form>
                <h2>
                {$title}
            </h2>
                <div class="mail-tools tooltip-demo m-t-md">
                    <button onclick="reload()" class="btn btn-white btn-sm" data-toggle="tooltip" data-placement="left" title="刷新邮件列表"><i class="fa fa-refresh"></i> 刷新</button>
                    <button onclick="setread()" class="btn btn-white btn-sm" data-toggle="tooltip" data-placement="top" title="标为已读"><i class="fa fa-eye"></i>
                    </button>
                    <button onclick="del()" class="btn btn-white btn-sm" data-toggle="tooltip" data-placement="top" title="删除"><i class="fa fa-trash-o"></i>
                    </button>

                </div>
            </div>
            <div class="mail-box">
                <form method="post" action="" class="form-horizontal m-t" id="mails">
                    <table class="table table-hover table-mail">
                        <tbody>
                          {:table_empty_list($list,'暂无数据!',4)}
                            {volist name='list' id='mail'}
                            <tr class="{if condition="$usebox==inbox and $mail->is_read==0"}unread{else}read{/if}">
                                <td class="check-mail">
                                    <input name="mail_ids[]" value="{$mail->mail_id}" type="checkbox" class="i-checks">
                                </td>

                                <td class="mail-ontact"><a href="javascript://">{$mail->target_user->user_name}</a>
                                </td>
                                <td class="mail-subject"><a href="{:url('admin/Mail/view',['mail_id'=>$mail.mail_id])}">{$mail->title}</a>
                                </td>
                                <td class="text-right mail-date">{$mail->send_time}</td>
                            </tr>
                            {/volist}

                        </tbody>
                    </table>
                    <div class="row" style="padding:2%; ">
                        <div class="col-sm-6">
                            <div class="dataTables_info" id="DataTables_Table_0_info" role="alert" aria-live="polite" aria-relevant="all">
                                每页显示 {:getPageSize()} 项，共 {$list->toArray()['total']} 项</div>
                        </div>
                        <div class="col-sm-6">
                            <div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
                                {$list->render()}

                            </div>

                        </div>
                    </div>
                </form>

            </div>
        </div>
    </div>
</div>
<script>
    function del() {
        if (confirm("您是否确认删除?")) {
            var postdata = $("#mails").serialize();
            if (postdata != '') {
                post({
                    url: "{:url('admin/Mail/del_multi')}",
                    data: postdata,
                    success: function(res) {
                        swal({
                            title: 'success',
                            text: res.message,
                            type: "success"
                        }, function() {
                            reload();
                        });
                    },
                    error: function(error) {
                        swal("错误", JSON.parse(error.responseText).message, "error");
                    }
                });
            }
        }
    }

    function setread() {
        var postdata = $("#mails").serialize();
        if (postdata != '') {
            post({
                url: "{:url('admin/Mail/read_multi')}",
                data: postdata,
                success: function(res) {
                    swal({
                        title: 'success',
                        text: res.message,
                        type: "success"
                    }, function() {
                        reload();
                    });
                },
                error: function(error) {
                    swal("错误", JSON.parse(error.responseText).message, "error");
                }
            });
        }
    }
</script>
<script src="/static/js/plugins/iCheck/icheck.min.js"></script>
<script>
    $(document).ready(function() {
        $(".i-checks").iCheck({
            checkboxClass: "icheckbox_square-green",
            radioClass: "iradio_square-green",
        })
    });
</script>
